<?php

namespace Xin\Process\Python;

trait ParseProgressBar
{
	/**
	 * @param string $data
	 * @return array|null
	 */
	public static function parseProgressBar(string $data): ?array
	{
		if (!preg_match('/(\d+)%.*?\s+(\d+)\/(\d+)\s\[(.*?), (.*?)\]/', $data, $matches) || !$matches) {
			return null;
		}

		return [
			'percent'       => $matches[1],
			'processed'     => $matches[2],
			'total'         => $matches[3],
			'expected_time' => $matches[4],
			'speed'         => $matches[5],
		];
	}
}
